#include <dlfcn.h>

#include <isa.h>
#include <memory/paddr.h>
#include <monitor/monitor.h>
extern CPU_state cpu;
void cpu_exec(uint64_t);
enum { DIFFTEST_TO_DUT, DIFFTEST_TO_REF };
void difftest_memcpy(uint32_t addr, void *buf, size_t n, bool direction)
{
    if(direction == DIFFTEST_TO_REF)
    {
        Log("%x,%lx", addr, n);
        char *buf_char = (char *)buf;
        for (int i = 0; i < n; i++)
        {
            paddr_write(addr + i, buf_char[i], 1);
        }
    }
    return ;
}

void difftest_regcpy(void *dut, bool direction)
{
    uint32_t* dut_regs = dut;
    if(direction == DIFFTEST_TO_DUT)
    {
        for (int i = 0; i < 32; i++)
            dut_regs[i] = cpu.gpr[i]._32;
        dut_regs[32] = cpu.pc;
    }
    else
    {
        for(int i = 0; i < 32; i++)
            cpu.gpr[i]._32 = dut_regs[i];
        cpu.pc = dut_regs[32];
    }
    return ;
}

void difftest_exec(uint32_t n)
{
    cpu_exec(n);
}

void difftest_raise_intr(uint32_t NO)
{
    return ;
}

void difftest_init(/*int port*/)
{
    /* Perform ISA dependent initialization. */
    void init_mem();
    void init_isa();
    init_mem();
    init_isa();
}

